import {defineStore} from "pinia";

type AppProps = {
  gLoadingId: string
  showGLoading: boolean
  requestLoadingId: string
  requestLoadingContent: string
  showRequestLoading: boolean
  refreshPage: boolean
}

const AppProps: AppProps = {
  gLoadingId: null,
  requestLoadingId: null,
  showRequestLoading: false,
  requestLoadingContent: '请求加载中...',
  showGLoading: false,
  refreshPage: false,
}

export const useAppStore = defineStore('AppStore', {
  state: (): AppProps => ({
    ...AppProps,
  }),
  actions: {
    setGLoadingId(id: string) {
      this.gLoadingId = id;
    },
    setShowGLoading(status: boolean) {
      this.showGLoading = status
    },
    setRequestLoadingId(id: string) {
      this.requestLoadingId = id;
    },
    setShowRequestLoading(status: boolean, content: string = '请求加载中...') {
      this.requestLoadingContent = content
      this.showRequestLoading = status
    },
    setRefreshPage(status: boolean) {
      this.refreshPage = status;
    }
  }
})
